<%@ page language="vb"  %>  
<%@ import namespace="system.drawing" %>  
<%@ import namespace="system.drawing.imaging" %>  
<%@ import namespace="system.drawing.drawing2d" %>  
 <html><head runat="server"></head></html>
 <script runat="server">
 Function GenerateCapatchaImage(ByVal imgName As String, ByVal text As String, Optional ByVal w As Integer = 95, Optional ByVal h As Integer = 35, Optional ByVal fontSize As Byte = 18, Optional ByVal bgcolor As String = "gray") As String
     
     Dim oBitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
     Dim oGraphic As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(oBitmap)
     Dim oColor As System.Drawing.Color

     Dim sColor As String = bgcolor
     Dim sText As String = text
     Dim sFont As String = "Pristina"

     Select Case sColor
         Case "red"
             oColor = System.Drawing.Color.Red
         Case "green"
             oColor = System.Drawing.Color.Green
         Case "navy"
             oColor = System.Drawing.Color.Navy
         Case "orange"
             oColor = System.Drawing.Color.Orange
         Case Else
             oColor = System.Drawing.Color.Gray
     End Select


     'Dim oBrush As New System.Drawing.SolidBrush(oColor)
         Dim bImg As System.Drawing.Image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/images/captcha-img.jpg"), True)
     Dim bBrush As New System.Drawing.TextureBrush(bImg)

     Dim oBrushWrite As New System.Drawing.SolidBrush(System.Drawing.Color.White)

     oGraphic.FillRectangle(bBrush, 0, 0, w, h)
     oGraphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias

     Dim oFont As New System.Drawing.Font(sFont, FontSize)
     Dim oPoint As New System.Drawing.PointF(3.0F, 3.0F)

     oGraphic.DrawString(sText, oFont, oBrushWrite, oPoint)

     'output to a specified image location
     'oBitmap.Save(HttpContext.Current.Server.MapPath("<%=AppPath%>/images/template-default/captcha/" & imgName & ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)

     'output to the response web page
     HttpContext.Current.Response.ContentType = "image/jpeg"
     oBitmap.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
     '*********************************************
     'Dim rcode As Integer = loadimagefromurl("", ezimage)
     oGraphic.Dispose()
     oBitmap.Dispose()
     '********************************************
 
     Return Nothing
 End Function
  
 </script>
 <% 
     
     Response.Clear() ' make sure Nothing has gone to the client  
    
     GenerateCapatchaImage(Session.SessionID, Request("code"), Request("w"), Request("h"), Request("fsize"))
       
     Response.End()
%>

